/****************************************************************
 ** Product  :   HP Subscriber Network Application Policy
 ** Module   :   gr-manager
 ** Date: Apr 10, 2015               
 ** Author: Huang xiaoji
 ** (C) Copyright 2015, Hewlett-Packard Company, All Rights Reserved.
 ** This software is the proprietary information of HP, Inc.  
 ** Use is subject to license terms.
 *****************************************************************
 ** Description:   
 **   Send trap message.
 **    
 ****************************************************************/
package com.hp.snap.gr.action.impl;

import com.hp.snap.gr.exception.ActionException;
import com.hp.snap.gr.model.jaxb.ActionType;
import com.hp.snap.gr.model.jaxb.SNMPTrapActionType;
import com.hp.snap.gr.utils.SNMPTrapHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 
 * Send trap message.
 * 
 * There are three parameter can be configured in the action: enterpriseOid, destination and content.
 * enterpriseOid: enterprise OID of trap message.
 * destination: destination list of trap, each destination should follow the format: <destination address>:[snmp version]:[snmp port]:<coummunity>
 * content: trap message content.
 * 
 * <P>
 * Version: 3.3 <br>
 * Author: Huang xiaoji 
 * Date: Apr 10, 2015
 * 
 * </P>
 * 
 **/
public class SNMPTrapActionHandler extends AbstractActionHandler {

    private static Logger logger = LoggerFactory.getLogger(SNMPTrapActionHandler.class);

    @Override
    public void execute(ActionType action,
                        Map<String, Object> actionPlanInputs,
                        Map<String, Object> actionPlanOutputs) throws ActionException {
        if (action instanceof SNMPTrapActionType) {
            SNMPTrapActionType actionType = (SNMPTrapActionType) action;

            logger.debug("invoke the SNMPTrapActionHandler, destinations: {}, enterpriseOID: {}, contents: {}",
                    new Object[]{actionType.getDestination(), actionType.getEnterpriseOid(), actionType.getContent()});

            SNMPTrapHelper.sendTrap(actionType.getEnterpriseOid(), actionType.getDestination(), actionType.getContent());
        }
    }

}
